package demo.proxy.dynamic.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

// 相当于Aspect
public class PayInvocationHandler implements InvocationHandler {
    Object target;

    public PayInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object res = method.invoke(target,args);// 原方法
        after();
        return res;
    }

    // Before Advice:
    private void before() {
        System.out.println("支付前的操作");
    }
    // After Advice:
    private void after() {
        System.out.println("支付后的操作");
    }
}
